import request from '../utils/request.js'
// 获取对应频道的详情文章
export const getArticleApi = ({channel_id,timestamp}) => {
  return request({
    url: '/v1_0/articles',
    method: 'GET',
    params: {
      channel_id,
      timestamp,
    }
  })
}

// 不感兴趣该篇文章
export const disLikeArticleApi = (id) => {
  return request({
    url: '/v1_0/article/dislikes',
    method: 'post',
    data: {
      target: id
    }
  })
}

// 反馈垃圾内容接口
export const reportsArticleApi = (id, type) => {
  return request({
    url: '/v1_0/article/reports',
    method: 'post',
    data: {
      target: id,
      type,
      remark: '举报的附加信息,正常是写一个输入框让用户输入的'
    }
  })
}



// 获取新闻详情的接口
export const detailApi = ({
  article_id
}) => {
  return request({
    url: `/v1_0/articles/${article_id}`,
    method: 'GET'
  })
}

// 关注作者的api
export function followedauthorApi(author_id) {
  return request({
    url: '/v1_0/user/followings',
    method: 'POST',
    data: {
      target: author_id
    }
  })
}

// 取关作者的api
export function unfollowedauthorApi(author_id) {
  return request({
    url: `/v1_0/user/followings/${author_id}`,
    method: 'DELETE',
  })
}

// 点赞文章Api
export function likeApi(target_id) {
  console.log(target_id)
  return request({
    url: '/v1_0/article/likings',
    method: 'POST',
    data: {
      target: target_id
    }
  })
}

// 取消点赞文章Api
export function unLikeApi(target_id) {
  console.log(target_id)
  return request({
    url: `/v1_0/article/likings/${target_id}`,
    method: 'DELETE',
  })
}

// 获取评论数据Api
export const getCommentApi = ({type,source,offset = null,limit = 10}) => {
  return request({
    url: '/v1_0/comments',
    method: 'GET',
    params: {
      type, // 评论类型，a-对文章(article)的评论，c-对评论(comment)的回复
      source,
      offset,
      limit
    }
  })
}

// 赞当前的评论
export const likeCommentApi = ({
  comment_id
}) => {
  return request({
    url: '/v1_0/comment/likings',
    method: 'POST',
    data: {
      target: comment_id
    }
  })
}

// 取消赞当前的评论
export const unlikeCommentApi = ({comment_id}) => {
  return request({
    url: `/v1_0/comment/likings/${comment_id}`,
    method: 'DELETE'
  })
}


// 添加评论接口
export const addCommetApi = ({
  article_id,
  content,
  art_id = null
}) => {
  let obj = {
    target: article_id,
    content,
  }
  if (art_id !== null) {
    obj.art_id = art_id
  }
  return request({
    url: '/v1_0/comments',
    method: 'POST',
    data: obj,
  })
}

// 收藏文章
export const startArticleApi = ({article_id})=>{
  return request({
    url:'/v1_0/article/collections',
    method:'POST',
    data:{
       target:article_id
    }
  })
}

// 取消收藏文章
export const unStartArticleApi = (article_id)=>{
  return request({
    url:`/v1_0/article/collections/${article_id}`,
    method:'DELETE',
  })
}
